package com.tdcy.biz.scmgt.service;

import java.util.Map;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.tdcy.biz.wxmgt.WxMgtConstant;
import com.tdcy.framework.util.StringUtils;
import com.tdcy.sys.dao.eo.ParamEO;
import com.tdcy.sys.service.IParamSvc;

/**
 */
@Service
public class WxPicTextService  {
	private final Logger logger = LoggerFactory.getLogger(this.getClass());

	@Resource
	IParamSvc paramSvc;

	@Transactional
	public void saveWxParam(Map<String, String> paraMap) {
		String appid = StringUtils.getString(paraMap, "appid");
		String appsecret = StringUtils.getString(paraMap, "appsecret");
		String token = StringUtils.getString(paraMap, "token");
		String aesKey = StringUtils.getString(paraMap, "aesKey");

		ParamEO p1 = paramSvc.getParam(WxMgtConstant.WXPARAM_APPID);
		if (p1 != null) {
			p1.setValue(appid);
			paramSvc.updateParam(p1);
		} else {
			p1 = new ParamEO();
			p1.setCode(WxMgtConstant.WXPARAM_APPID);
			p1.setValue(appid);
			paramSvc.addParam(p1);
		}

		ParamEO p2 = paramSvc.getParam(WxMgtConstant.WXPARAM_APPSECRET);
		if (p2 != null) {
			p2.setValue(appsecret);
			paramSvc.updateParam(p2);
		} else {
			p2 = new ParamEO();
			p2.setCode(WxMgtConstant.WXPARAM_APPSECRET);
			p2.setValue(appsecret);
			paramSvc.addParam(p2);
		}

		ParamEO p3 = paramSvc.getParam(WxMgtConstant.WXPARAM_TOKEN);
		if (p3 != null) {
			p3.setValue(token);
			paramSvc.updateParam(p3);
		} else {
			p3 = new ParamEO();
			p3.setCode(WxMgtConstant.WXPARAM_TOKEN);
			p3.setValue(token);
			paramSvc.addParam(p3);
		}

		ParamEO p4 = paramSvc.getParam(WxMgtConstant.WXPARAM_AESKEY);
		if (p4 != null) {
			p4.setValue(aesKey);
			paramSvc.updateParam(p4);
		} else {
			p4 = new ParamEO();
			p4.setCode(WxMgtConstant.WXPARAM_AESKEY);
			p4.setValue(aesKey);
			paramSvc.addParam(p4);
		}
	}

}
